package com.xinrui.attendanceweb.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xinrui.attendanceweb.mapper.ClassesMapper;
import com.xinrui.attendanceweb.mapper.StudentMapper;
import com.xinrui.attendanceweb.pojo.Classes;
import com.xinrui.attendanceweb.pojo.Student;
import com.xinrui.attendanceweb.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private ClassesMapper classesMapper;
    @Override
    public PageInfo<Student> pageQueryStudent(Integer pageCurrent, Integer pageSize) {
        // 开始分页
        Page<Student> studentPage = PageHelper.startPage(pageCurrent, pageSize);
        List<Student> studentList = studentMapper.findAll();
        PageInfo<Student> studentPageInfo = new PageInfo<>(studentList);//分页信息
        studentPageInfo.getList().forEach(student -> {
            // Classes className= classesMapper.findClassById(student.getId());
            // System.err.println(className.getName());
            // String name = classesMapper.findClassById(student.getId()).getName();
            // student.setClasses(name);
        });
        return studentPageInfo;
    }

    @Override
    public Student findStudentById(Integer id) {
        return studentMapper.findStudentById(id);
    }

    @Override
    public boolean update(Student student) {
        return studentMapper.updateStudent(student);
    }

    @Override
    public boolean save(Student student) {
        return studentMapper.saveStudent(student);
    }

    @Override
    public boolean deleteStudent(Integer id) {
        return studentMapper.remove(id);
    }
}
